
define([
    "jquery",
    "IO",
    "bootbox"
], function ($, IO, bootbox) {

    $(function () {

        var year_1 = 1;
        var year_2 = 2;
        var year_3 = 3;

        var activity_mid=$("#activity_mid_hidden").val();
        $("#btnSave1").click(function(){

            parameter2(year_1,activity_mid);
        });
        $("#btnSave2").click(function(){
            parameter2(year_2,activity_mid);
        });
        $("#btnSave3").click(function(){
            parameter2(year_3,activity_mid);
        });

    });
    function parameter2(year_id,activity_mid){
        var id;
        if(year_id==1){
            id=0;
        }
        else if(year_id==2)
        {
            id=1;
        }
        else {
            id=2;
        }
        var tiexian=$(".row2-input").eq(id).val()==""?"0":$(".row2-input").eq(id).val();
        var baoxian=$(".row3-input").eq(id).val()==""?"0":$(".row3-input").eq(id).val();
        var fajin=$(".row4-input").eq(id).val()==""?"0":$(".row4-input").eq(id).val();
        var group_mid= $("#selectgroup1 option:selected").attr("data-id");
        if(group_mid=="undefined"){
            alert("请选择公司");
            return;
        }

        var params={};
        params.tiexian=tiexian;
        params.baoxian=baoxian;
        params.fajin=fajin;
        params.activity_mid=activity_mid;
        params.year_id=year_id;
        params.group_mid=group_mid;
        if(isNaN(params.tiexian)||isNaN(params.baoxian)||isNaN(params.fajin)){
            alert("请输入数字");
            return;
        }

        if(activity_mid!=""){
            if(tiexian!=""&&baoxian!=""&&fajin!=""){

                IO.post("/shapan/api/OtherDecisionsAdd",params,function(d){
                    if(d.code==0){
                        alert("提交成功");
                    }
                })
            }
            else{
                alert("请填写完整的参数!!");
            }
        }
        else {
            alert("请创建活动");
        }
    }
});